<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>Excel导出</title>
<link rel="stylesheet" type="text/css" media="screen" th:href="@{/webjars/star/css/buttons.css}" />
</head>
<body>
  选择要下载的数据：
  <select id="templateKey" multiple="multiple">
    <option value="student" data-handle="testExport">学生</option>
    <option value="teacher" data-handle="testExport">教师</option>
    <option value="transportOrder" data-handle="orderService">订单</option>
    <option value="a">其他不存在的</option>
  </select>
  <input type="button" class="button green" value="下载" id="downloadExcelBtn">
  <script type="text/javascript" th:src="@{/webjars/star/js/jquery.min-1.11.3.js}"></script>
  <script type="text/javascript">
  $(function(){
    $("#downloadExcelBtn").click(function(){
      var templateKey = $("#templateKey").val();
      var url = '/download/excel/data?params=';
      if(templateKey.length>1){
        var keys="";
        var handles="";
        $("#templateKey option:selected").each(function(i, j){
          keys+=","+j.value;
          handles+="," + $(j).attr("data-handle");
        });
        var params = {"key":keys.substring(1),"handle":handles.substring(1)};
        url+=encodeURI(JSON.stringify(params));
      }else{
        var params = {"key":$("#templateKey option:selected").val(),"handle":$("#templateKey option:selected").attr("data-handle")};
        url+=encodeURI(JSON.stringify(params));
      }
      window.open(url);
    });
  });
  </script>
</body>
</html>